#include <bits/stdc++.h>
using namespace std;
int T,n,m,l,V,p,ans_cars,ans_supervisions;
void deal(double d,double v){
    if(v<=V)return;
    else ans_cars++;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        ans_cars=0;ans_supervisions=0;
        scanf("%d%d%d%d",&n,&m,&l,&V);
        int car[n+1][4];
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&car[i][0],&car[i][1],&car[i][2]);
            deal(car[i][0],car[i][1]);
            car[i][3]=0;
        }
        for(int i=0;i<m;i++){
            bool flag=true;
            scanf("%d",&p);
            for(int j=0;j<n;j++){
                if(car[j][3]==0&&car[i][1])
                    if(car[i][0]<p){
                        car[j][3]=1;
                        flag=false;
                    }
            }
            if(flag)ans_supervisions++;
        }
        printf("%d %d",ans_cars,ans_supervisions);
    }
    return 0;
}
